package com.bittech.base;

/**
 * @Author: yuisama
 * @Date: 2019-07-04 18:06
 * @Description:字符串变量拼接与常量拼接的区别
 * 字符串只要有变量参与"+"操作，编译后会优化为StringBuilder的append
 * 在调用toString()的过程中会new String，因此只要变量拼接，一定返回堆上的新字符串
 */
public class StringDemo1 {
    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = "ab";
        String str3 = "c";
        String str4 = str2 + str3;
        String str5 = str2 + str3;
        String str6 = "ab" + "c";
        System.out.println(str1==("ab"+"c"));
        System.out.println(str4.equals("abc"));
        System.out.println(str4==(str2+str3));
        System.out.println(str4 == str5);
        System.out.println(str1 == str6);
        System.out.println(str4==("ab"+"c"));
        System.out.println(str1 == str4);
        System.out.println(str1 == "abc");
    }
}
